import { http } from "@/uni-sub-base/service/request.js"
let serviceName = "File/"
import { getBaseUrls } from "@/utils/appUrl.js"
import storage from "@/uni-sub-base/utils/storage.js"
import store from "@/store/index.js"
//上传图片
export function uploadImage(obj) {
    return new Promise((resolve, reject) => {
        let token = store.state.token
        //先取store 的值
        if (!token || token == null || token == "") {
            //没有的话取token
            token = storage.getCache("token")
        }
        if (!token || token == null || token == "") {
            //没有的话取webInfo
            let webInfo = storage.getCache("webInfo")
            if (webInfo != null) {
                token = webInfo.Token
            }
        }
        uni.uploadFile({
            url: getBaseUrls().basePublicUrl + serviceName + "formUpload",
            header: {
                Authorization: "Bearer " + token,
            },
            filePath: obj.filePath,
            name: "file",
            formData: obj.formData,
            success: (res) => {
                if (res.statusCode == 200) {
                    resolve(JSON.parse(res.data))
                }
            },
        })
    })
}
export function Upload(data) {
    return http.post({
        url: getBaseUrls().basePublicUrl + serviceName + "Upload",
        data,
    })
}
